package com.metaera.app.ui.adapters;

import android.content.Context;
import android.content.res.Resources;
import android.widget.ImageView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.metaera.app.R;
import com.metaera.app.data.model.ActivityListResponse;
import com.metaera.app.ui.activities.ActivityDetailsActivity;
import com.metaera.app.utils.DateUtils;
import com.metaera.app.utils.image.GlideApp;

import androidx.annotation.NonNull;

public class ActivityListAdapter extends BaseQuickAdapter<ActivityListResponse, BaseViewHolder> {

    public ActivityListAdapter() {
        super(R.layout.item_home_activity);

        setOnItemClickListener((adapter, view, position) -> {
            Context context = view.getContext();
            context.startActivity(ActivityDetailsActivity.newInstance(context, getItem(position).getId()));
        });
    }

    @Override
    protected void convert(@NonNull BaseViewHolder holder, ActivityListResponse item) {
        ImageView ivCover = holder.getView(R.id.iv_cover);
        Resources resources = ivCover.getContext().getResources();

        holder.setText(R.id.tv_title, item.getTitle())
                .setText(R.id.tv_location, item.getOrganizer())
                .setText(R.id.tv_status, resources.getStringArray(R.array.activity_state)[item.getStatus()])
                .setEnabled(R.id.tv_status, item.getStatus() != 2)
                .setText(R.id.tv_date,
                        DateUtils.getTime(item.getStart_time_stamp(), DateUtils.PATTERN_9)
                                + "~"
                                + DateUtils.getTime(item.getEnd_time_stamp(), DateUtils.PATTERN_9));

        GlideApp.with(ivCover).load(item.getPic()).normal().into(ivCover);
    }

}
